home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / IEditor / Generators / C / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  5.5 KB  |  210 lines

  1. /// Includes
  2. #define INTUI_V36_NAMES_ONLY
  3.  
  4. #include <exec/types.h>                 // exec
  5. #include <exec/lists.h>
  6. #include <exec/nodes.h>
  7. #include <dos/dos.h>                    // dos
  8. #include <dos/dostags.h>
  9. #include <libraries/reqtools.h>         // libraries
  10. #include <clib/exec_protos.h>           // protos
  11. #include <clib/dos_protos.h>
  12. #include <clib/reqtools_protos.h>
  13. #include <pragmas/exec_pragmas.h>       // pragmas
  14. #include <pragmas/dos_pragmas.h>
  15. #include <pragmas/reqtools_pragmas.h>
  16.  
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <ctype.h>
  20.  
  21. #include "DEV_IE:Generators/defs.h"
  22. #include "DEV_IE:Include/IEditor.h"
  23. #include "DEV_IE:Generators/C/Protos.h"
  24. ///
  25.  
  26.  
  27. /// AskFile
  28. BOOL AskFile( UBYTE *File, struct IE_Data *IE )
  29. {
  30.     BOOL    ret = TRUE;
  31.     BPTR    lock;
  32.  
  33.     if( lock = Lock( File, ACCESS_READ )) {
  34.  
  35.     UnLock( lock );
  36.  
  37.     ULONG   tags[] = { RT_ReqPos, REQPOS_CENTERSCR, RT_Underscore, '_',
  38.                RT_Screen, IE->ScreenData->Screen, TAG_DONE };
  39.  
  40.     ret = rtEZRequest( "%s alreay exists.\n"
  41.                "Overwrite?",
  42.                "_Yes|_No",
  43.                NULL, (struct TagItem *)tags,
  44.                FilePart( File )
  45.              );
  46.     }
  47.  
  48.     return( ret );
  49. }
  50. ///
  51.  
  52. /// WriteList
  53. void WriteList( struct GenFiles *Files, struct MinList *List, UBYTE *Label, UWORD Num, struct IE_Data *IE )
  54. {
  55.     struct GadgetScelta *gs;
  56.     UWORD                cnt;
  57.  
  58.     if( Num ) {
  59.  
  60.     FPrintf( Files->XDef, "extern struct MinList %sList;\n", Label );
  61.  
  62.     FPrintf( Files->Std, "\nstruct Node %sNodes[] = {\n\t", Label );
  63.  
  64.     gs = List->mlh_Head;
  65.  
  66.     if( Num == 1 ) {
  67.         FPrintf( Files->Std, "(struct Node *)&%sList.mlh_Tail, (struct Node *)&%sList.mlh_Head, 0, 0, ",
  68.              Label, Label );
  69.  
  70.         if( IE->SrcFlags & LOCALIZE )
  71.         FPuts( Files->Std, "(STRPTR)" );
  72.  
  73.         if( Prefs.Flags & SMART_STR )
  74.         FPrintf( Files->Std, "%s", (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, gs->gs_Testo ))->ID );
  75.         else
  76.         FPrintf( Files->Std, "\"%s\"", gs->gs_Testo );
  77.  
  78.         FPuts( Files->Std, " };\n" );
  79.     } else {
  80.  
  81.         FPrintf( Files->Std, "&%sNodes[1], (struct Node *)&%sList.mlh_Head, 0, 0, ",
  82.              Label, Label );
  83.  
  84.         if( IE->SrcFlags & LOCALIZE )
  85.         FPuts( Files->Std, "(STRPTR)" );
  86.  
  87.         if( Prefs.Flags & SMART_STR )
  88.         FPrintf( Files->Std, "%s", (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, gs->gs_Testo ))->ID );
  89.         else
  90.         FPrintf( Files->Std, "\"%s\"", gs->gs_Testo );
  91.  
  92.         FPuts( Files->Std, ",\n" );
  93.  
  94.         for( cnt = 1; cnt < Num - 1; cnt++ ) {
  95.  
  96.         gs = gs->gs_Node.ln_Succ;
  97.  
  98.         FPrintf( Files->Std, "\t&%sNodes[%ld], &%sNodes[%ld], 0, 0, ",
  99.              Label, cnt + 1, Label, cnt - 1 );
  100.  
  101.         if( IE->SrcFlags & LOCALIZE )
  102.             FPuts( Files->Std, "(STRPTR)" );
  103.  
  104.         if( Prefs.Flags & SMART_STR )
  105.             FPrintf( Files->Std, "%s", (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, gs->gs_Testo ))->ID );
  106.         else
  107.             FPrintf( Files->Std, "\"%s\"", gs->gs_Testo );
  108.  
  109.         FPuts( Files->Std, ",\n" );
  110.         }
  111.  
  112.         gs = gs->gs_Node.ln_Succ;
  113.         FPrintf( Files->Std, "\t(struct Node *)&%sList.mlh_Tail, &%sNodes[%ld], 0, 0, ",
  114.              Label, Label, Num - 2 );
  115.  
  116.         if( IE->SrcFlags & LOCALIZE )
  117.         FPuts( Files->Std, "(STRPTR)" );
  118.  
  119.         if( Prefs.Flags & SMART_STR )
  120.         FPrintf( Files->Std, "%s", (( *IE->Functions->FindString )( &IE->Locale->ExtraStrings, gs->gs_Testo ))->ID );
  121.         else
  122.         FPrintf( Files->Std, "\"%s\"", gs->gs_Testo );
  123.  
  124.         FPuts( Files->Std, " };\n" );
  125.     }
  126.  
  127.     FPrintf( Files->Std, "\nstruct MinList %sList = {\n"
  128.                  "\t(struct MinNode *)&%sNodes[0], (struct MinNode *)NULL, (struct MinNode *)&%sNodes[%ld] };\n",
  129.          Label, Label, Label, Num - 1 );
  130.     }
  131. }
  132. ///
  133.  
  134. //      Locale stuff
  135. /// WriteLocaleH
  136. void WriteLocaleH( struct GenFiles *Files, struct IE_Data *IE, STRPTR FileName )
  137. {
  138.     BPTR    file;
  139.  
  140.     if( file = Open( FileName, MODE_NEWFILE )) {
  141.     struct LocaleStr       *str;
  142.     TEXT                    buffer[80];
  143.     UBYTE                  *from, *to;
  144.     ULONG                   num = 0;
  145.  
  146.     from = FilePart( FileName );
  147.     to   = buffer;
  148.  
  149.     while( *from ) {
  150.         UBYTE   b;
  151.  
  152.         b = *from++;
  153.  
  154.         if( b == '.' )
  155.         *to++ = '_';
  156.         else
  157.         *to++ = toupper( b );
  158.     }
  159.  
  160.     *to = '\0';
  161.  
  162.  
  163.     FPrintf( file, "#ifndef %s\n#define %s\n\n"
  164.                "/* This file was generated automatically by IEditor!\n"
  165.                "   Do NOT edit by hand!\n"
  166.                " */\n\n"
  167.                "/*************************************************************************/\n\n"
  168.                "#ifndef EXEC_TYPES_H\n"
  169.                "#include <exec/types.h>\n"
  170.                "#endif\n\n"
  171.                "#ifdef CATCOMP_ARRAY\n"
  172.                "#undef CATCOMP_NUMBERS\n"
  173.                "#define CATCOMP_NUMBERS\n"
  174.                "#endif\n\n"
  175.                "struct CatCompArrayType\n"
  176.                "{\n"
  177.                "\tLONG\tcca_ID;\n"
  178.                "\tSTRPTR\tcca_Str;\n"
  179.                "};\n"
  180.                "\n"
  181.                "/*************************************************************************/\n\n"
  182.                "#ifdef CATCOMP_NUMBERS\n\n",
  183.                buffer, buffer );
  184.  
  185.  
  186.     for( str = IE->Locale->ExtraStrings.mlh_Head; str->Node.ln_Succ; str = str->Node.ln_Succ )
  187.         FPrintf( file, "#define %s %ld\n", str->ID, num++ );
  188.  
  189.     FPuts( file, "\n"
  190.              "#endif /* CATCOMP_NUMBERS */\n"
  191.              "\n"
  192.              "/*************************************************************************/\n\n"
  193.              "#ifdef CATCOMP_ARRAY\n\n"
  194.              "struct CatCompArrayType CatCompArray[] =\n"
  195.              "{\n" );
  196.  
  197.     for( str = IE->Locale->ExtraStrings.mlh_Head; str->Node.ln_Succ; str = str->Node.ln_Succ )
  198.         FPrintf( file, "\t{%s,\"%s\"},\n", str->ID, str->Node.ln_Name );
  199.  
  200.     FPrintf( file, "};\n\n"
  201.                "#endif /* CATCOMP_ARRAY */\n"
  202.                "\n"
  203.                "#endif /* %s */\n",
  204.          buffer );
  205.  
  206.     Close( file );
  207.     }
  208. }
  209. ///
  210.